import { useEffect } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import { useGameStore } from '@/store/game-store';
import { Layout } from '@/components/layout';
import { HomePage } from '@/pages/home-page';
import { CultivationPage } from '@/pages/cultivation-page';
import { BattlePage } from '@/pages/battle-page';
import { InventoryPage } from '@/pages/inventory-page';
import { QuestPage } from '@/pages/quest-page';
import { SocialPage } from '@/pages/social-page';
import { AdminPage } from '@/pages/admin-page';
import { CharacterCreationPage } from '@/pages/character-creation-page';

function App() {
  const { player, initializeGame } = useGameStore();

  useEffect(() => {
    initializeGame();
  }, [initializeGame]);

  // 如果玩家名字是默认的，显示角色创建页面
  if (player.name === '无名修士') {
    return <CharacterCreationPage />;
  }

  return (
    <Layout>
      <Routes>
        <Route path="/" element={<HomePage />} />
        <Route path="/cultivation" element={<CultivationPage />} />
        <Route path="/battle" element={<BattlePage />} />
        <Route path="/inventory" element={<InventoryPage />} />
        <Route path="/quest" element={<QuestPage />} />
        <Route path="/social" element={<SocialPage />} />
        <Route path="/admin" element={<AdminPage />} />
        <Route path="*" element={<Navigate to="/" replace />} />
      </Routes>
    </Layout>
  );
}

export default App;